package com.sense.ioc.bean;

import com.sense.ioc.register.IocRegister;

import java.lang.reflect.Field;

/**
 * Creator: LanJian (lanjian860217@gmail.com)
 * Date: 11-2-16
 * Time: 下午7:14
 */
public class ReferenceDefinition {
    private Class referenceClass;
    private Field field;
    private Object target;

    public ReferenceDefinition(Class referenceClass, Field field, Object target) {
        this.referenceClass = referenceClass;
        this.field = field;
        this.target = target;
    }

    public Class getReferenceClass() {
        return referenceClass;
    }

    public void setReferenceClass(Class referenceClass) {
        this.referenceClass = referenceClass;
    }

    public Field getField() {
        return field;
    }

    public void setField(Field field) {
        this.field = field;
    }

    public Object getTarget() {
        return target;
    }

    public void setTarget(Object target) {
        this.target = target;
    }

    public void fixReference() throws IllegalAccessException {
        field.set(getTarget(), IocRegister.findBean(referenceClass));
    }
}
